<template>
    <base-dialog  v-bind="$attrs" v-on="$listeners" :title="title" size="mini" @submit="toAdd" :disabled="disabled">
        <el-form  ref="elForm" label-width="100px" :model="formData" :rules="rules" :disabled="disabled">
            <el-form-item label="栏目名称" prop="comset">
                <dept-select-tree v-model="formData.comset" :disable-branch-nodes="true" placeholder="请选择栏目名称"  v-bind="$attrs" dept-type="other" :all-dept-list="comsetList" v-if="loading"></dept-select-tree>
            </el-form-item>
            <el-form-item label="应用名称" prop="name">
                <el-input v-model="formData.name"></el-input>
            </el-form-item>
            <el-form-item label="图标" prop="icon">
                <my-upload-image v-model="formData.icon"></my-upload-image>
            </el-form-item>
            <el-form-item label="链接" prop="link">
                <el-input v-model="formData.link"></el-input>
            </el-form-item>
            <el-form-item label="工作流" prop="workflow">
                <dept-select-tree v-model="workflow" :disable-branch-nodes="true" placeholder="请选择工作流"  v-bind="$attrs" dept-type="other" :all-dept-list="workflowsList" v-if="loading" :multiple="true"></dept-select-tree>
            </el-form-item>
            <el-form-item label="排序">
                <el-input-number v-model="formData.no_order"></el-input-number>
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-radio-group v-model="formData.status">
                    <el-radio :label="true">启用</el-radio>
                    <el-radio :label="false">禁用</el-radio>
                </el-radio-group>
            </el-form-item>
        </el-form>
    </base-dialog>
</template>
<script>
    import BaseDialog from "@/components/Common/BaseDialog";
    import DetailDialog from "@/mixins/DetailDialog";
    import XEUtils from "xe-utils";
    import category from "@/api/systemManagement/useful/category/index"
    import common from "@/api/common/index"
    import MyUploadImage from "../../../../components/Common/MyUploadImage";
    import DeptSelectTree from '@/components/Common/DeptSelectTree'
    export default {
        name:"DetailDialog",
        mixins:[DetailDialog],
        props:["parentList"],
        data(){
          return {
              formData:{
                  comset:undefined,
                  name:"",
                  icon:"",
                  link:"",
                  workflow:undefined,
                  no_order:0,
                  status:true,

              },
              rules:{
                  name: [
                      { required: true, message: "名称不能为空", trigger: "blur" }
                  ],
                  comset:[ {required: true,message: "栏目名称不能为空",trigger: "blur"}]
              },
              userList:[],
              loading:false,
              comsetList:[],
              workflowsList:[]
          }
        },
        created() {
            this.getCategoryList()
        },
        components: { DeptSelectTree, MyUploadImage, BaseDialog},
        computed:{
            title() {
                return this.disabled?'查看':this.formData.id?"编辑":"新增"
            },
            workflow:{
                get(){
                    return this.formData.workflow?this.formData.workflow.split(","):[]
                },
                set(v){
                    this.formData.workflow = v?v.join(","):""
                }
            }
        },
        methods:{
            getCategoryList(){
                category.getCategorySimple().then(res=>{
                    this.comsetList= res.data;
                    this.getWorkflowsSimple()
                })
            },
            getWorkflowsSimple(){
              console.log("------------common.getWorkflowsSimple",common.getWorkflowsSimple)
              common.getWorkflowsSimple().then(res=>{
                    this.workflowsList = res.data;
                    this.loading = true
                })
            }
        }
    }
</script>
